package com.ironman.analyze.core.compute;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.ironman.analyze.core.compute.base.BaseComputer;
import com.ironman.analyze.core.compute.base.BaseVectorComputer;
import com.ironman.analyze.core.compute.entity.YawWindowData;
import com.ironman.analyze.core.context.TrainingContext;
import com.ironman.analyze.core.handler.YawPostHandler;
import com.ironman.common.entity.YawData;
import com.ironman.common.params.YawParam;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * 船首向计算
 */
@Slf4j
public class YawVectorComputer extends BaseVectorComputer<YawData> implements BaseComputer<YawData, YawWindowData> {

    private final YawPostHandler yawPostHandler;

    public YawVectorComputer(TrainingContext trainingContext, YawParam yawParam) {
        super(yawParam.getWindowSize(), trainingContext);
        this.yawPostHandler = new YawPostHandler(yawParam);
    }

    @Override
    public void computeWindowData(List<YawData> dataList) {
        for (YawData yawData : dataList) {
            windowData(yawData, new BiConsumer<Date, Double>() {
                @Override
                public void accept(Date ts, Double yaw) {
                    YawWindowData yawWindowData = new YawWindowData(ts, yaw);
                    yawPostHandler.handler(yawWindowData, new Consumer<YawWindowData>() {
                        @Override
                        public void accept(YawWindowData yawWindowData) {
                            syncData(yawWindowData);
                        }
                    });
                }
            });
        }
    }

    @Override
    public void syncData(YawWindowData windowData) {
        getTrainingContext().getYawWindowDataMap().put(windowData.getTs(), windowData);
    }

    public static void main(String[] args) {
        YawVectorComputer yawComputer = new YawVectorComputer(null, null);

        List<YawData> yawDataList = ListUtil.of(
                new YawData(DateUtil.parse("2024-12-15 12:00:00", DatePattern.NORM_DATETIME_PATTERN), 1.212),
                new YawData(DateUtil.parse("2024-12-15 12:00:00", DatePattern.NORM_DATETIME_PATTERN), 1.212),
                new YawData(DateUtil.parse("2024-12-15 12:00:00", DatePattern.NORM_DATETIME_PATTERN), 1.212),
                new YawData(DateUtil.parse("2024-12-15 12:00:00", DatePattern.NORM_DATETIME_PATTERN), 1.212),
                new YawData(DateUtil.parse("2024-12-15 12:00:00", DatePattern.NORM_DATETIME_PATTERN), 1.212),
                new YawData(DateUtil.parse("2024-12-15 12:00:00", DatePattern.NORM_DATETIME_PATTERN), 1.212),
                new YawData(DateUtil.parse("2024-12-15 12:00:00", DatePattern.NORM_DATETIME_PATTERN), 1.212),
                new YawData(DateUtil.parse("2024-12-15 12:00:00", DatePattern.NORM_DATETIME_PATTERN), 1.212),
                new YawData(DateUtil.parse("2024-12-15 12:00:00", DatePattern.NORM_DATETIME_PATTERN), 1.212),
                new YawData(DateUtil.parse("2024-12-15 12:00:00", DatePattern.NORM_DATETIME_PATTERN), 1.212),
                new YawData(DateUtil.parse("2024-12-15 12:00:01", DatePattern.NORM_DATETIME_PATTERN), 1.111),
                new YawData(DateUtil.parse("2024-12-15 12:00:01", DatePattern.NORM_DATETIME_PATTERN), 1.111),
                new YawData(DateUtil.parse("2024-12-15 12:00:01", DatePattern.NORM_DATETIME_PATTERN), 1.111),
                new YawData(DateUtil.parse("2024-12-15 12:00:01", DatePattern.NORM_DATETIME_PATTERN), 1.111),
                new YawData(DateUtil.parse("2024-12-15 12:00:01", DatePattern.NORM_DATETIME_PATTERN), 1.111),
                new YawData(DateUtil.parse("2024-12-15 12:00:01", DatePattern.NORM_DATETIME_PATTERN), 1.111),
                new YawData(DateUtil.parse("2024-12-15 12:00:01", DatePattern.NORM_DATETIME_PATTERN), 1.111),
                new YawData(DateUtil.parse("2024-12-15 12:00:01", DatePattern.NORM_DATETIME_PATTERN), 1.111),
                new YawData(DateUtil.parse("2024-12-15 12:00:01", DatePattern.NORM_DATETIME_PATTERN), 1.111),
                new YawData(DateUtil.parse("2024-12-15 12:00:01", DatePattern.NORM_DATETIME_PATTERN), 1.111)

        );
        yawComputer.computeWindowData(yawDataList);
    }


}
